﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SIEGate.Core.Stats
{
    /// <summary>
    /// A Stats Cluster that is not registered with the central Stats service.  This is useful for things that do not have IDs
    /// </summary>
    // Example non-ID case:  ConcentratorBase that is not an adapter.
    public class UnregisteredCluster : Cluster
    {
        public UnregisteredCluster()
            : base(uint.MaxValue)
        {
        }

        // Register only registers with the UnregisteredCluster, not with the StatDispatcher
        protected override StatInst Register(Func<string> getOwnerName, string statName, Type statType, params object[] args)
        {
            if (!m_statInstances.ContainsKey(statType))
            {
                m_statInstances.Add(statType, new Dictionary<string, StatInst>());
            }
            if (m_statInstances[statType].ContainsKey(statName))
            {
                return m_statInstances[statType][statName];
            }
            StatInst result = Stats.StatDispatcher.InstantiateStat(getOwnerName, statName, statType, args);
            m_statInstances[statType].Add(statName, result);
            return result;
        }
    }
}
